Given two lists, we would like to be able to stick them together,
which is what Cat (short for ``concatenate'')
does. For example, #math141#Cat~[1, 2]~[3, 4] is
[1, 2, 3, 4]. It can be defined using Foldr:
#math142#
Cat~xs~ys |
= |
Foldr~Cons~ys~xs |
|
So
#math143#
Cat~[1, 2]~[3, 4];SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp; |
|
= |
Foldr~Cons~[3, 4]~[1, 2] |
|
|
= |
Cons~1~(Foldr~Cons~[3, 4]~[2]) |
|
|
= |
Cons~1~(Cons~2~(Foldr~Cons~[3, 4]~[ ])) |
|
|
= |
Cons~1~(Cons~2~[3, 4]) |
|
|
= |
[#tex2html_wrap_indisplay2524#[1, 2]#tex2html_wrap_indisplay2525#Foldr#tex2html_wrap_indisplay2526#@8<#1#>#tex2html_wrap_indisplay2527#[3, 4]#tex2html_wrap_indisplay2528#[3, 4][@#tex2html_wrap_indisplay2529#Unlistize#tex2html_wrap_indisplay2530#@]] |
|
The TEX code for 32 is suspiciously similar to its mathematical
definition.